package com.appirio.timeentry.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.datepicker.client.DateBox;



/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
@SuppressWarnings("deprecation")
public class TimeEntry implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);
	
	private VerticalPanel mainPanel = new VerticalPanel(); 
	private AbsolutePanel totalPanel = new AbsolutePanel(); 
	private DockPanel navPanel = new DockPanel();  
	private HorizontalPanel topPanel = new HorizontalPanel();  
	private Label totalLabel = new Label("0.00"); 
	private FlexTable flexEntryTable = new FlexTable(); 
	private FlexTable flexCurrentTable = new FlexTable(); 
	private Image logo = new Image(); 

	
	private void addRow() { 
	  
		int row = flexEntryTable.getRowCount(); 
		  
		final ListBox lbMilestones = new ListBox(false); 
		final ListBox lbProjects = new ListBox(false); 
		lbProjects.addItem("-- Select a Project --"); 
		  
		// create the time input fields for all 7 days 
		final TextBox day1 = new TextBox(); 
		day1.setValue("0"); 
		day1.setWidth("50px"); 
		day1.setEnabled(false); 
		final TextBox day2 = new TextBox(); 
		day2.setValue("0"); 
		day2.setWidth("50px"); 
		day2.setEnabled(false); 
		final TextBox day3 = new TextBox(); 
		day3.setValue("0"); 
		day3.setWidth("50px"); 
		day3.setEnabled(false); 
		final TextBox day4 = new TextBox(); 
		day4.setValue("0"); 
		day4.setWidth("50px"); 
		day4.setEnabled(false); 
		final TextBox day5 = new TextBox(); 
		day5.setValue("0"); 
		day5.setWidth("50px"); 
		day5.setEnabled(false); 
		final TextBox day6 = new TextBox(); 
		day6.setValue("0"); 
		day6.setWidth("50px"); 
		day6.setEnabled(false); 
		final TextBox day7 = new TextBox(); 
		day7.setValue("0"); 
		day7.setWidth("50px"); 
		day7.setEnabled(false); 
		 
		// add all of the widgets to the flex table 
		flexEntryTable.setWidget(row, 0, lbProjects); 
		flexEntryTable.setWidget(row, 1, lbMilestones); 
		flexEntryTable.setWidget(row, 2, new CheckBox()); 
		flexEntryTable.setWidget(row, 3, day1); 
		flexEntryTable.setWidget(row, 4, day2); 
		flexEntryTable.setWidget(row, 5, day3); 
		flexEntryTable.setWidget(row, 6, day4); 
		flexEntryTable.setWidget(row, 7, day5); 
		flexEntryTable.setWidget(row, 8, day6); 
		flexEntryTable.setWidget(row, 9, day7); 
		flexEntryTable.setWidget(row, 10, new Label("0.00")); 
	}
	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		logo.setUrl("images/appirioLogo.jpg"); 
		 
		HorizontalPanel userPanel = new HorizontalPanel(); 
		Anchor logOutLink = new Anchor("Sign Out"); 
		Label separator = new Label("|");
		
		separator.setStyleName("separator");  
		userPanel.add(new Label("edsv14@gmail.com")); 
		userPanel.add(separator); 
		userPanel.add(logOutLink); 
		 
		topPanel.setWidth("1000px"); 
		topPanel.add(logo); 
		topPanel.add(userPanel); 
		topPanel.setCellHorizontalAlignment(userPanel, HasHorizontalAlignment.ALIGN_RIGHT); 
	
		// set up a horizontal panel to hold the date picker
		HorizontalPanel leftNav = new HorizontalPanel(); 
		leftNav.setSpacing(5); 
		leftNav.add(new Label("Week Start Date")); 
		DateBox dateBox = new DateBox(); 
		dateBox.setWidth("100px"); 
		dateBox.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("M/d/yyyy")));  
		leftNav.add(dateBox);
						
		// set up a horizontal panel to hold the Add and Save buttons 
		HorizontalPanel buttonPanel = new HorizontalPanel(); 
		buttonPanel.setSpacing(5); 
		Button addRowButton = new Button("Add Row"); 
		Button saveButton = new Button("Save"); 
		buttonPanel.add(addRowButton); 
		buttonPanel.add(saveButton);
		
		// set up another horizontal panel to dock all of the buttons to the right 
		final HorizontalPanel rightNav = new HorizontalPanel(); 
		rightNav.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); 
		rightNav.setWidth("100%"); 
		rightNav.add(buttonPanel); 
		 
		// add all of the navigation panels to the dock panel 
		navPanel.setWidth("1000px"); 
		navPanel.add(leftNav, DockPanel.WEST); 
		navPanel.add(rightNav, DockPanel.EAST);
		
		// set up a horizontal panel to hold the grand total 
		totalPanel.setSize("1000px","50px"); 
		totalPanel.add(new Label("Total:"), 900, 25); 
		totalPanel.add(totalLabel, 950, 25);
		
		// set the width of the table to expand the size of the navPanel 
		flexEntryTable.setWidth("100%"); 
		// set the style for the table to be accessed in the css 
		flexEntryTable.setStylePrimaryName("timeEntryTable"); 
		 
		// add the columns and headers 
		flexEntryTable.setText(0, 0, "Project"); 
		flexEntryTable.setText(0, 1, "Milestone"); 
		flexEntryTable.setText(0, 2, "Billable?"); 
		flexEntryTable.setText(0, 3, "Mon"); 
		flexEntryTable.setText(0, 4, "Tue"); 
		flexEntryTable.setText(0, 5, "Wed"); 
		flexEntryTable.setText(0, 6, "Thu"); 
		flexEntryTable.setText(0, 7, "Fri"); 
		flexEntryTable.setText(0, 8, "Sat"); 
		flexEntryTable.setText(0, 9, "Sun"); 
		flexEntryTable.setText(0, 10, "Total");
		
		VerticalPanel tab1Content = new VerticalPanel(); 
		tab1Content.add(navPanel); 
		tab1Content.add(flexEntryTable); 
		tab1Content.add(totalPanel);
		
		DecoratedTabPanel tabPanel = new DecoratedTabPanel(); 
		tabPanel.setWidth("100%"); 
		tabPanel.setAnimationEnabled(true); 
		tabPanel.add(tab1Content, "Enter Time"); 
		tabPanel.selectTab(0);
		
		// add the navpanel and flex table to the main panel
		mainPanel.add(topPanel); 
		mainPanel.add(tabPanel);
		
		// associate the main panel with the HTML host page. 
		RootPanel.get("timeentryUI").add(mainPanel);
		
		//flexEntryTable.setStylePrimaryName("timeEntryTable");
		 
	}
}
